<?php

namespace App\Http\Middleware;

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Cookie;
use Closure;

class CheckCustomer
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $userId = Cookie::get('user_id', '');
        $authId = Cookie::get('auth', 0);
        logger($userId);
        logger($authId);
        logger(Config::get('const.authCustomer', 0));
        if ($userId === '' || $authId != Config::get('const.authCustomer', 0)) {
            return redirect('login');
        }
        return $next($request);
    }
}
